<?php
/* [DoYouHaoBaby!] (C)Dianniu From 2010.
   this($)*/

!defined('DYHB_PATH') && exit;

class TemplateGtkGladeWidgetCompiler_GtkDialog extends TemplateGtkGladeWidgetCompiler_GtkWindow{

	protected function compileCreateWidget_(TemplateGtkGladeWidget $oObject){
		$sCompiled=TemplateGtkGladeWidgetCompiler_GtkWindow::compileCreateWidget_($oObject);
		$sWidgetClass=$oObject->getWidgetClass();
		$sVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oObject);
		$oTopBox=$oObject->removeTemplateObj(0);//  跳过 默认的子窗体 vbox， 以便插入来自 Glade 的窗体
		if($oTopBox){
			$oTopBoxWidget=$oTopBox->getWidget();
			$oIterator=$oTopBoxWidget->createTemplateObjIterator();// 查找下级窗体
			$oIterator->first();
			while(!$oIterator->isDone()){
				$oChild=$oIterator->current();
				$oChildWidget=$oChild->getWidget();
				if($oChildWidget->getWidgetClass()=='GtkHButtonBox'){// 按钮 区域
					$oBtnIterator=$oChildWidget->createTemplateObjIterator();// 依次加入各个按钮
					$oBtnIterator->first();
					while(!$oBtnIterator->isDone()){
						$oBtn=$oBtnIterator->current();
						$oBtnIterator->next();
						$oObject->addTemplateObj($oBtn->getWidget(),$oBtn->getPacking());// 加入子窗体
						$sCompiled.=$this->packingBtn_($oObject,$oBtn->getWidget(),$oBtn->getPacking());// 打包
					}
				}
				else{// 主区域
					$oObject->addTemplateObj($oChildWidget,$oChild->getPacking());// 加入子窗体
					$sCompiled.=$this->packingMain_($oObject,$oChildWidget,$oChild->getPacking());// 打包
				}
				$oIterator->next();
			}
			$oTopBoxWidget->getTemplateObj(0);
		}
		// $sCompiled.= "\t\t{$sVariableName}->remove({$sVariableName}->get_child());";

		// 模态
		$this->setBool_($oObject,$sCompiled,'has_separator');
		return $sCompiled;
	}

	protected function packingBtn_(TemplateGtkGladeWidget $oParentWidget,TemplateGtkGladeWidget $oChildWidget,TemplateGtkGladeWidgetPacking $oPacking){
		$sParentVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oParentWidget);// 父/子 窗体变量名
		$sChildWidgetVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oChildWidget);
		$sChildWidgetId=$oChildWidget->getWidgetId();
		$nResponseId=$oChildWidget->getProperty('response_id');
		$sCompiled="\t\t{$sChildWidgetVariableName}=\$this->getWidget('{$sChildWidgetId}',\$arrObjectForSignal);";
		$sCompiled.="\t\t{$sParentVariableName}->add_action_widget({$sChildWidgetVariableName},{$nResponseId});";
		if($oPacking->getProperty('secondary')){$sCompiled.="\t\t{$sParentVariableName}->action_area->set_child_secondary({$sChildWidgetVariableName},true);";}// 二级
		return $sCompiled;
	}

	protected function packingMain_(TemplateGtkGladeWidget $oParentWidget,TemplateGtkGladeWidget $oChildWidget, TemplateGtkGladeWidgetPacking $oPacking){
		$sParentVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oParentWidget);// 父/子 窗体变量名
		$sChildWidgetVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oChildWidget);
		$sChildWidgetId=$oChildWidget->getWidgetId();
		$sCompiled="\t\t{$sChildWidgetVariableName}=\$this->getWidget('{$sChildWidgetId}',\$arrObjectForSignal);";
		$sCompiled.="\t\t{$sParentVariableName}->vbox->add({$sChildWidgetVariableName});";
		return $sCompiled;
	}

	protected function compileChildWidgetPacking_(TemplateGtkGladeWidget $oParentWidget,TemplateGtkGladeWidget $oChildWidget,TemplateGtkGladeWidgetPacking $oPacking){ }

	static public function regToProcessorManager(ITemplateObjProcessorManager $oManager){
		$oManager->regProcessor(str_replace('TemplateGtkGladeWidgetCompiler_','',__CLASS__),__CLASS__);
	}

}
